<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="./css/aui.css" />
    <link rel="stylesheet" type="text/css" href="./css/aui-slide.css" />
    <link rel="stylesheet" type="text/css" href="./css/font-awesome.css" />
    <link rel="stylesheet" type="text/css" href="./css/style.css" />
    <script type="text/javascript" src="./script/jquery.min.js"></script>
    <script type="text/javascript" src="./script/doT.min.js"></script>
    <script type="text/javascript" src="./script/base.js"></script>
    <script type="text/javascript" src="./script/api.js"></script>
</head>

<body>
    <header class="header" style="padding-top:2rem; height:4rem;">
        <div class="header-l aui-pull-left" onclick="closeWin()">
           <i class="fa fa-angle-left"></i>
        </div>
        <div class="search">
            <label>
            <span class="aui-iconfont aui-icon-search"></span>
            <input type="text" placeholder="请输入商品名称">
        </label>
        </div>
        <div class="header-r aui-pull-right" tapmode onclick="cart()">
            <i class="fa fa-shopping-cart"></i>
        </div>
    </header>

    <style>
        html,
        body {
            height: 100%;
        }
    </style>

    <div class="classify" style="height:calc(100% - 4rem);">


            <div class="classify-l" id="list"></div>
                <script type="text/template" id="template">
                <ul>
                    {{~it:value:index}}
                    <li id='act{{=index}}' onclick="check_detail({{=index}})">{{=value.name}}</li>
                    {{~}}
                </ul>
                </script>

            <div class="classify-r"  id="list2"></div>
                <script type="text/template" id="template2">
                <ul>
                    {{~it.children:value:index}}
                    <li onclick="buy_detail({{=value.class_id}})">
                        <img src={{=value.image}} alt="">
                        <p>{{=value.name}}</p>
                    </li>
                    {{~}}
                </ul>
                </script>

    </div>



    <!-- <div class="classify" style="height:calc(100% - 4rem);">
    <div class="classify-l">
        <ul>
            <li>防盗门</li>
            <li class="active">安全门</li>
            <li>卷帘门</li>

        </ul>
    </div>
    <div class="classify-r">
        <ul>
            <li>
                <img src="./images/goods-3.jpg" alt="">
                <p>防盗门</p>
            </li>
            <li>
                <img src="./images/goods-3.jpg" alt="">
                <p>防盗门</p>
            </li>

        </ul>
    </div>
</div> -->


</body>
<script type="text/javascript" src="./script/api.js"></script>
<script type="text/javascript">
    var data;

    function cart() {
        var delay = 0;
        if (api.systemType != 'ios') {
            delay = 300;
        }
        api.openWin({
            name: 'cart',
            url: './cart.html',
            bounces: false,
            delay: delay,
            slidBackEnabled: true,
            vScrollBarEnabled: false,
            progress: {
                type: "page"
            }
        });
    }


    apiready = function() {
        getData();

    }

    function getData() {

        api.ajax({
            url: webAddress + '/a/mall/Class/index',
            method: 'post',
            headers:{
                TOKEN: token
              }

        }, function(ret, err) {
            if (ret) {
              // console.log(JSON.stringify(ret));
                data = ret.result;
                var template = $api.byId('template');
                var dotFn = doT.template(template.innerHTML);
                var html = dotFn(data);
                var list = $api.byId('list');
                $api.html(list, html);
                check_detail(0);

            } else {
                alert(JSON.stringify(err));
            }
        });

    }

    function check_detail(index) {
      $('li').removeClass();
      $('#act'+index).addClass("active");

        var value = data[index];

        var template = $api.byId('template2');
        var dotFn = doT.template(template.innerHTML);
        var html = dotFn(value);
        var list = $api.byId('list2');
        $api.html(list, html);
    }

    function buy_detail(index) {
        api.openWin({
            name: 'commlist',
            url: './commlist.html',
            pageParam: {
                index: index
            }
        });



    }





    function closeWin() {
        api.closeWin({});
    }
</script>

</html>
